import random


class Student:
    def __init__(self, sid, name, age):
        self.sid = sid
        self.name = name
        self.age = age

    def __str__(self):
        return f"学生学号：{self.sid} 学生姓名：{self.name} 学生年龄：{self.age} "


class StudentManage:
    def __init__(self):
        self.l = []

    def add_student(self):
        names = ["小张", "小李", "小王", "小唐", "小孙", "小孔", "小董", "小高", "小刘", "小徐"]
        for i in range(10):
            s = Student(sid=101 + i, name=names[i], age=random.randint(18, 22))
            d = {
                "sid": s.sid,
                "name": s.name,
                "age": s.age
            }
            self.l.append(d)

    def show_student(self):
        for e in self.l:
            print(e)

    def get_max_min_age(self):
        for i in range(len(self.l)-1):
            max_index = i
            for j in range(i+1, len(self.l)):
                if self.l[max_index]["age"] > self.l[j]["age"]:
                    max_index = j
            if max_index != i:
                age = self.l[i]
                self.l[i] = self.l[max_index]
                self.l[max_index] = age
        for e in self.l:
            print(e)


def main():
    sm = StudentManage()
    sm.add_student()
    sm.show_student()
    print("# "*20)
    sm.get_max_min_age()


if __name__ == '__main__':
    main()

